/**
 * 系统路由
 */
import Vue from 'vue'
import VueRouter from 'vue-router'
import PlainTemplate from 'views/common/Layout/PlainTemplate'
import FullTemplate from 'views/common/Layout/FullTemplate'
import Login from '../views/common/Login'
import Register from '../views/common/Register'
import Fillup from '../views/common/Fillup'
import Home from '../views/common/Home'
import Iframe from '../views/common/Iframe'
import auth from './auth'

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) {
    return originalPush.call(this, location, onResolve, onReject)
  }
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    component: PlainTemplate,
    children: [
      {
        path: '/login',
        component: Login
      },
      {
        path: '/register',
        name: 'Register',
        component: Register,
        children: [
          {
            path: '/register-school',
            name: 'RegisterSchool',
            component: () =>
              import(
                /* webpackChunkName: "register-school" */ '../views/common/Register/School'
              )
          },
          {
            path: '/register-company',
            name: 'RegisterCompany',
            component: () =>
              import(
                /* webpackChunkName: "register-company" */ '../views/common/Register/Company'
              )
          },
          {
            path: '/register-student',
            name: 'RegisterStudent',
            component: () =>
              import(
                /* webpackChunkName: "register-student" */ '../views/common/Register/Student'
              )
          }
        ]
      },
      {
        path: '/fillup',
        name: 'Fillup',
        component: Fillup,
        children: [
          {
            path: '/fillup-school',
            name: 'FillupSchool',
            component: () =>
              import(
                /* webpackChunkName: "fillup-school" */ '../views/common/Fillup/School'
              )
          },
          {
            path: '/fillup-company',
            name: 'FillupCompany',
            component: () =>
              import(
                /* webpackChunkName: "fillup-company" */ '../views/common/Fillup/Company'
              )
          },
          {
            path: '/fillup-student',
            name: 'FillupStudent',
            component: () =>
              import(
                /* webpackChunkName: "fillup-student" */ '../views/common/Fillup/Student'
              )
          }
        ]
      },
      {
        path: '/find-pass',
        name: 'FindPass',
        component: () =>
          import(/* webpackChunkName: "find-pass" */ '../views/common/FindPass')
      }
    ]
  },
  {
    path: '/',
    component: FullTemplate,
    redirect: '/home',
    children: [
      {
        path: '/home',
        name: 'Home',
        component: Home
      },
      {
        path: '/my-notice',
        name: 'MyNotice',
        component: () =>
          import(/* webpackChunkName: "my-notice" */ '../views/common/MyNotice')
      },
      {
        path: '/my-notice/detail/:id',
        name: 'MyNoticeDetail',
        component: () =>
          import(
            /* webpackChunkName: "my-notice-detail" */ '../views/common/MyNoticeDetail'
          )
      },
      {
        path: '/school/info',
        name: 'SchoolInfo',
        component: () =>
          import(
            /* webpackChunkName: "school-info" */ '../views/school/Information'
          )
      },
      {
        path: '/school/student-list',
        name: 'StudentList',
        component: () =>
          import(
            /* webpackChunkName: "student-list" */ '../views/school/StudentList'
          )
      },
      {
        path: '/school/student-list/detail/:id',
        name: 'StudentDetail',
        component: () =>
          import(
            /* webpackChunkName: "student-detail" */ '../views/school/StudentDetail'
          )
      },
      {
        path: '/school/cooperation',
        name: 'Cooperation',
        component: () =>
          import(
            /* webpackChunkName: "cooperation" */ '../views/school/Cooperation'
          )
      },
      {
        path: '/company/info',
        name: 'CompanyInfo',
        component: () =>
          import(
            /* webpackChunkName: "company-info" */ '../views/company/Information'
          )
      },
      {
        path: '/company/job-list',
        name: 'CompanyJobList',
        component: () =>
          import(
            /* webpackChunkName: "company-job-list" */ '../views/company/JobList'
          )
      },
      {
        path: '/company/job-list/edit',
        name: 'CompanyJobEdit',
        component: () =>
          import(
            /* webpackChunkName: "company-job-edit" */ '../views/company/JobEdit'
          )
      },
      {
        path: '/company/job-list/post',
        name: 'CompanyJobPost',
        component: () =>
          import(
            /* webpackChunkName: "company-job-post" */ '../views/company/JobPost'
          )
      },
      {
        path: '/company/job-list/post/resume-detail/:id',
        name: 'CompanyResumeDetail',
        component: () =>
          import(
            /* webpackChunkName: "company-resume-detail" */ '../views/company/ResumeDetail'
          )
      },
      {
        path: '/student/info',
        name: 'StudentInfo',
        component: () =>
          import(
            /* webpackChunkName: "student-info" */ '../views/student/Information'
          )
      },
      {
        path: '/myPractice/job-list',
        name: 'StudentJobList',
        component: () =>
          import(
            /* webpackChunkName: "student-job-list" */ '../views/student/JobList'
          )
      },
      {
        path: '/myPractice/job-post',
        name: 'StudentJobPost',
        component: () =>
          import(
            /* webpackChunkName: "student-job-post" */ '../views/student/JobPost'
          )
      },
      {
        path: '/myPractice/practice',
        name: 'StudentPractice',
        component: () =>
          import(
            /* webpackChunkName: "student-practice" */ '../views/student/Practice'
          )
      },
      {
        path: '/myPractice/practice/job-detail',
        name: 'StudentJobDetail',
        component: () =>
          import(
            /* webpackChunkName: "student-job-detail" */ '../views/student/JobDetail'
          )
      },
      {
        path: '/myPractice/resume',
        name: 'StudentResume',
        component: () =>
          import(
            /* webpackChunkName: "student-resume" */ '../views/student/Resume'
          )
      },
      {
        path: '/company-admin/project',
        component: Iframe
      },
      {
        path: '/company-admin/template',
        component: Iframe
      },
      {
        path: '/company-admin/user',
        component: Iframe
      },
      {
        path: '/student-course/list',
        component: Iframe
      },
      {
        path: '/student-course/mine',
        component: Iframe
      },
      {
        path: '/student-exam/list',
        component: Iframe
      },
      {
        path: '/student-exam/train',
        component: Iframe
      },
      {
        path: '/student-exam/result',
        component: Iframe
      },
      {
        path: '/student-oper/task',
        component: Iframe
      },
      {
        path: '/student-oper/performance',
        component: Iframe
      }
    ]
  },
  {
    path: '/test',
    name: 'Test',
    component: () => import(/* webpackChunkName: "test" */ '../views/Test')
  },
  {
    path: '/401',
    name: '401',
    component: () => import(/* webpackChunkName: "401" */ '../views/common/401')
  },
  {
    path: '*',
    name: '404',
    component: () => import(/* webpackChunkName: "404" */ '../views/common/404')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach(async (to, from, next) => {
  await auth(to, next)
})

export default router
